{% from 'lenta/macros.jinja' import form_field_error_list %}


{% macro view_lenta_link (lenta, label=None) -%}

    <a href="{{ url_for('lenta.view_lenta',
                        namespace=lenta.namespace,
                        lenta_id=lenta.id) }}">{{ lenta.name if label is none else label }}</a>

{%- endmacro %}

{% macro view_lenta_href (lenta) -%}
    {{ url_for('lenta.view_lenta', namespace=lenta.namespace, lenta_id=lenta.id) }}
{%- endmacro %}


{% macro edit_lenta_link (lenta, label) -%}

    <a href="{{ url_for('lenta.edit_lenta',
                        lenta_id=lenta.id) }}">{{ label }}</a>

{%- endmacro %}

{% macro edit_lenta_href (lenta) -%}
    {{ url_for('lenta.edit_lenta', lenta_id=lenta.id) }}
{%- endmacro %}


{% macro delete_lenta_link (lenta, label) -%}

    <a href="{{ url_for('lenta.delete_lenta',
                        lenta_id=lenta.id) }}">{{ label }}</a>

{%- endmacro %}


{% macro lenta_info_link (lenta, label) -%}

    <a href="{{ url_for('lenta.lenta_info',
                        namespace=lenta.namespace,
                        lenta_id=lenta.id) }}">{{ label }}</a>

{%- endmacro %}

{% macro lenta_info_href (lenta) -%}
    {{url_for('lenta.lenta_info', namespace=lenta.namespace, lenta_id=lenta.id)}}
{%- endmacro %}

{% macro lenta_all_tags_href (lenta) -%}
    {{url_for('lenta.view_all_tags_for_lenta', namespace=lenta.namespace, lenta_id=lenta.id)}}
{%- endmacro %}


{% macro lenta_form (lenta, errors) -%}

    <div id="name_div" class="form-element {{ 'error' if errors is defined and errors.name }}">
        
        <label for="name_id"></label>
        <input name="name" id="name_id" class="title" placeholder="Name your Lenta" value="{{ lenta.name if lenta is defined }}" />
        <div class="error">
        {{ form_field_error_list (errors, 'name') }}
        </div>
    </div>

    <div id="desc_div" class="form-element {{ 'error' if errors is defined and errors.desc }}">
        
        <label for="desc_id"></label>
        <textarea name="desc" id="desc_id" class="text" placeholder="Describe your Lenta">{{lenta.desc if lenta is defined }}</textarea>
        <div class="error">
        {{ form_field_error_list (errors, 'desc') }}
		</div>
    </div>
{%- endmacro %}


{% macro lenta_form_js (debug) -%}

	$("#lenta_form").validate({
		rules: {
	    	name: {
	       		required: true,
	       		maxlength: 100
	    	},
	    	desc: {
	    		required: true
	    	}
		},
		messages: {
	    	name: {
	        	required: "Specify name",
	        	maxlength: "NAme is limited to 100 symbols"
	    	},
	    	desc: {
	        	required: "Describe lenta"
	    	}
		},
		wrapper: "div",
		errorElement: "label",
		errorClass: "error-clientside",
	{% if debug %}
		debug: true,
		submitHandler: function(form) {
	    	console.debug(form);
		},
	{% endif %}	
	});
{%- endmacro %}